﻿@using System.Reflection
@using System.Diagnostics
<div class="has-background-light">
    <div class="hero">
        <div class="hero-body has-background-blazor has-text-white has-text-centered">
            <h1 class="title is-size-1 has-text-white">Blazor Sortable</h1>
            <p>An integration of the <a class="has-text-white has-text-weight-bold" href="https://github.com/SortableJS/Sortable">SortableJS library</a> with Blazor.</p>
        </div>

        <a class="button is-dark" href="https://github.com/the-urlist/blazorsortable" target="_blank">
            <span class="icon">
                <i class="fab fa-github"></i>
            </span>
            <span>View the original project on GitHub</span>
        </a>
        
        <a class="button is-dark" href="https://github.com/AlexNek/BlazorSortableList" target="_blank">
            <span class="icon">
                <i class="fab fa-github"></i>
            </span>
            <span>View the extended project on GitHub. Package V@_version</span>
        </a>
    </div>
</div>

@code {

    private string? _version;

    /// <summary>
    /// Method invoked when the component is ready to start, having received its
    /// initial parameters from its parent in the render tree.
    /// Override this method if you will perform an asynchronous operation and
    /// want the component to refresh when that operation is completed.
    /// </summary>
    /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> representing any asynchronous operation.</returns>
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        var assembly = typeof(ISortableListItemMover).Assembly;
        _version = assembly.GetName().Version?.ToString();

        var gitVersionInformationType = assembly.GetType("GitVersionInformation");
        if (gitVersionInformationType != null)
        {
            var fieldInfo = gitVersionInformationType.GetField("InformationalVersion");
            var version = fieldInfo?.GetValue(null);
            _version = version?.ToString();
        }

        // var fields = gitVersionInformationType.GetFields();

        // foreach (var field in fields)
        // {
        //     Trace.WriteLine(string.Format("{0}: {1}", field.Name, field.GetValue(null)));
        // }
    }

}
